package com.guoheng.hazard.sys.notice;


import com.guoheng.hazard.common.base.Result;
import com.guoheng.hazard.sys.model.dto.IdDTO;
import com.guoheng.hazard.sys.model.dto.PageDTO;
import io.swagger.annotations.Api;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 类功能描述:　通知公告控制层
 *
 * @author fbl
 * @date 2019-10-11 9:30
 */
@RestController
@Validated
@Api(value = "通知公告")
public class NoticeController {

    @Resource
    NoticeService noticeService;

    /**
     * 根据id删除通知
     *
     * @param idDTO 主键
     * @return
     */
    @PostMapping(value = "basic/notice/delete")
    public Result delete(@RequestBody @Valid IdDTO idDTO) {
        return noticeService.deleteByPrimaryKey(idDTO.getId());
    }

    /**
     * 根据id查询通知
     *
     * @param idDTO 主键
     * @return
     */
    @PostMapping(value = "basic/notice/queryById")
    public Result queryById(@RequestBody @Valid IdDTO idDTO) {
        return noticeService.selectByPrimaryKey(idDTO.getId());
    }


    /**
     * 根据类型查询通知
     *
     * @param pageDTO 通知公告
     * @return
     */
    @PostMapping(value = "basic/notice/query")
    public Result query(@RequestBody  @Valid PageDTO pageDTO) {
        return noticeService.queryNoticeByType(pageDTO);
    }

    /**
     * 根据id编辑通知
     *
     * @param noticeDTO 通知公告
     * @return
     */
    @PostMapping(value = "basic/notice/update")
    public Result update(@RequestBody @Valid NoticeDTO noticeDTO) {
        return noticeService.updateByPrimaryKeySelective(noticeDTO);
    }

    /**
     * 新增通知
     *
     * @param noticeDTO 通知公告
     * @return
     */
    @PostMapping(value = "basic/notice/insert")
    public Result insert(@RequestBody @Valid NoticeDTO noticeDTO) {
        return noticeService.insertSelective(noticeDTO);
    }


}
